package com.alibaba.citrus.cr.common.enums.ordercenter;

import com.google.common.collect.Lists;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
public enum ReturnOrderTypeEnum {
    RE_ORDER("ZRE2", "销售公司退货订单"),
    RE_LOGISTIC_ORDER("ZRE3", "销售公司物流退货订单"),

    // 一盘货新增枚举
    RE_FEE_ORDER("ZRE4", "销售公司免费订单退货"),
    RE_ECOMMERCE_ORDER("ZRE5", "电商退货订单"),
    RE_ORDER_GROUP("ZRE", "集团退货订单"),
    RE_ORDER_FREE_GROUP("ZREF", "集团免费销售订单退货"),
    ;

    private final String code;
    private final String desc;

    ReturnOrderTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ReturnOrderTypeEnum of(String code) {
        return Arrays.stream(ReturnOrderTypeEnum.values()).filter(source -> Objects.equals(code, source.getCode())).findFirst().orElse(null);
    }

    public static ReturnOrderTypeEnum companyOrderOf(String code) {
        return of(companyOrderCodes().stream().filter(source -> Objects.equals(code, source)).findFirst().orElse(null));
    }

    public static String descByCode(String code) {
        ReturnOrderTypeEnum typeEnum = of(code);
        return Objects.nonNull(typeEnum) ? typeEnum.getDesc() : null;
    }

    public static List<String> codes() {
        return Arrays.stream(ReturnOrderTypeEnum.values()).map(ReturnOrderTypeEnum::getCode).collect(Collectors.toList());
    }

    public static List<String> companyOrderCodes() {
        return Lists.newArrayList(RE_ORDER.getCode(), RE_LOGISTIC_ORDER.getCode(), RE_FEE_ORDER.getCode(), RE_ECOMMERCE_ORDER.getCode());
    }

    public static List<String> groupOrderCodes() {
        return Lists.newArrayList(RE_ORDER_GROUP.getCode(), RE_ORDER_FREE_GROUP.getCode());
    }
}
